fix(render): store valid diff structure for single-pane views#313
Merged
esmuellert merged 1 commit intomainfrom Mar 7, 2026
Merged
fix(render): store valid diff structure for single-pane views#313esmuellert merged 1 commit intomainfrom
esmuellert merged 1 commit intomainfrom
Conversation
show_untracked_file() and similar single-pane functions stored {} as
stored_diff_result, missing the required .changes and .moves fields.
When resume_diff() reused this value after tab cycling, render_diff()
crashed on ipairs(nil) because {}.changes is nil.
Replace {} with {changes={}, moves={}} in side_by_side.lua and
inline_view.lua to conform to the diff result schema. Add E2E test
that reproduces the exact PR #309 scenario.
Closes #309
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
esmuellert
added a commit
that referenced
this pull request
Mar 7, 2026
## Summary Fixes `E5108: Lua: attempt to get length of field 'changes' (a nil value)` crash in `find_hunk_at_cursor()` when invoking hunk operations (stage/unstage/discard) while `stored_diff_result.changes` is nil. ## Root Cause `find_hunk_at_cursor()` checked `#diff_result.changes == 0` without first verifying `.changes` is non-nil. This crashes when `stored_diff_result` exists but `.changes` is nil — the same class of bug fixed in PR #313 for `render_diff()`. ## Changes - Added nil guard: `if not diff_result.changes or #diff_result.changes == 0 then` ## Testing - Same pattern already validated in PR #313 - Single-line defensive fix with no behavioral change when `.changes` is present
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the crash reported in #309 — cycling tabs with an untracked file open in CodeDiff causes
render_diff()to crash onipairs(nil).Root Cause
show_untracked_file()(and similar single-pane functions) stored{}asstored_diff_result, missing the required.changesand.movesfields. Whenresume_diff()reused this value after tab cycling (no changedtick change → no recompute),render_diff()crashed because{}.changesisnil.Changes
side_by_side.lua: Replace{}with{changes={}, moves={}}inshow_single_file()inline_view.lua: Same fix in both inline single-file pathslayout_spec.lua: Update 2 tests that asserted the old buggynilbehaviortab_cycle_untracked.lua(new): E2E test reproducing the exact PR fix(render): handle nil changes when cycling tabs #309 scenario — verified to fail without fix, pass with fixTesting
stored_diff_result.changesis{}(notnil) immediately aftershow_untracked_file()suspend_diff→resume_diff→render_diff) exercised end-to-endCloses #309